package com.mes.task.service;


import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bstek.dorado.annotation.DataProvider;
import com.bstek.dorado.data.provider.Page;
import com.mes.common.service.BasicService;
import com.mes.task.dao.iface.IOperationTaskDao;
import com.mes.task.dao.iface.ITaskDao;
import com.mes.task.domain.OperationTask;
import com.mes.task.domain.TaskPart;
import com.mes.util.ScheduleUtil;

@Service
public class OperationTaskService extends BasicService<OperationTask> {

	@Autowired
	IOperationTaskDao operationTaskDao;
	@Autowired
	ITaskDao taskDao;
	@Resource
	private ScheduleUtil scheduleUtil;
	/**
	 * @author lcs
	 * @see 用于AO任务管理界面（AOTaskManger）界面工序任务tab页面获取数据
	 * @param page
	 * @param parameters
	 * @throws Exception
	 */
	@DataProvider
	public void getOperationTasks(Page<OperationTask> page, Map<String, Object> parameters) throws Exception {

		String taskUid = (String) parameters.get("taskUid");
		List<OperationTask> operationTasks = this.operationTaskDao
		.getOperationTasksByParentUid(taskUid);
		if (operationTasks != null && 0 < operationTasks.size()) {
				scheduleUtil.initPage(page, operationTasks);
			
		}
	

	}
	
	
	@DataProvider
	public OperationTask getOperationTaskByUuid(String operationTaskUid)
			throws Exception {
		OperationTask operationTask = operationTaskDao.getById(operationTaskUid);
		return operationTask;
	}
	
	@DataProvider
	public List<OperationTask> getOperationTasksByPartTaskUid(String partTaskUid)
			throws Exception {
		List<OperationTask> list = operationTaskDao.getOperationTasksByPartTaskUid(partTaskUid, false);
		return list;
	}
	
	@DataProvider
	public void getOperationTaskByCondition(Page<OperationTask> page, Map<String, Object> params){
		try {
			operationTaskDao.getOperationTaskByCondition(page, params);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	

}
